﻿<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <CustomAction
    Id="BramNuyts.WebApp.BlobCache"
    Location="CommandUI.Ribbon">
    <CommandUIExtension>
      <CommandUIDefinitions>
        <CommandUIDefinition Location="Ribbon.Templates._children">
          <GroupTemplate Id="Ribbon.Templates.NewGroupInExistingTab.OneLargeExample">
            <Layout Title="NewGroupInExistingTabOneLarge" LayoutTitle="NewGroupInExistingTabOneLarge">
              <Section Alignment="Top" Type="OneRow">
                <Row>
                  <ControlRef DisplayMode="Large" TemplateAlias="Button1" />
                </Row>
              </Section>
            </Layout>
          </GroupTemplate>
        </CommandUIDefinition>
        <CommandUIDefinition Location="Ribbon.WebApp.Scaling._children">
          <MaxSize
            Id="BramNuyts.WebApp.BlobCache.Group.MaxSize"
            Sequence="15"
            GroupId="BramNuyts.WebApp.BlobCache.Group"
            Size="NewGroupInExistingTabOneLarge" />
        </CommandUIDefinition>
        <CommandUIDefinition Location="Ribbon.WebApp.Groups._children">
          <Group
            Id="BramNuyts.WebApp.BlobCache.Group"
            Sequence="50"
            Description="Custom group to keep custom commands"
            Title="BramNuyts"
            Template="Ribbon.Templates.NewGroupInExistingTab.OneLargeExample">
            <Controls Id="BramNuyts.WebApp.BlobCache.Group.Controls">
              <Button
                Id="BramNuyts.WebApp.BlobCache.Group.ManageBlobCache"
                Command="BramNuyts.WebApp.BlobCache.Command.ManageBlobCache"
                Sequence="10"
                ToolTipTitle="Web Application BlobCache"
                ToolTipDescription="Configure the blobcache for a specific Web application."
                Image32by32="/_layouts/images/centraladmin_systemsettings_farmmanagement_32x32.png"
                LabelText="BlobCache Management"
                TemplateAlias="Button1" />
            </Controls>
          </Group>
        </CommandUIDefinition>
      </CommandUIDefinitions>
      <CommandUIHandlers>
        <CommandUIHandler
          Command="BramNuyts.WebApp.BlobCache.Command.ManageBlobCache"
          CommandAction="javascript:
          function portal_modalDialogClosedCallback(result, value) { 
            if(result === SP.UI.DialogResult.OK) { 
                SP.UI.Notify.addNotification('Settings successfully saved'); 
            } 
            if(result === SP.UI.DialogResult.cancel) { 
                SP.UI.Notify.addNotification('Action canceled');        
            } 
          }
          function manageBlobCache()
          {
            var $v_0 = SP.UI.Admin.WebApplicationPageComponent.get_selectedItem();
            var options = SP.UI.$create_DialogOptions();
            options.url = '/_admin/BramNuyts/BlobCacheManager.aspx?Id=' + $v_0.getAttribute('Id');
            options.width = '600';
            options.dialogReturnValueCallback = Function.createDelegate(null, portal_modalDialogClosedCallback);
            SP.UI.ModalDialog.showModalDialog(options);
          }
          manageBlobCache();"
          EnabledScript="javascript:
          function checkButton()
          {
            var $v_0 = SP.UI.Admin.WebApplicationPageComponent.get_selectedItem();
            if ($v_0 !== null)
            {
              $v_1 = ($v_0.getAttribute('IsCentralAdmin'))
              if ($v_1 === 'true')
              {
                return false;
              }
              else
              {
                return true;
              }
            }
            else
            {
              return false;
            }
            return false;
          }
          checkButton();"
          />
      </CommandUIHandlers>
    </CommandUIExtension>
  </CustomAction>
</Elements>
